/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.Image;

public class ThrowingObject {

    public static final double GRAVITY = 5.0;
    private int _damage;
    private int _weight;
    private double _throwAngle;
    private double _thrownPower;
    private double _t = 0;
    private boolean _isRuning;

    public ThrowingObject() {
        _isRuning = true;
    }

    public void setThrowParameter(double throwAngle, double thrownPower) {
        _throwAngle = throwAngle;
        _thrownPower = thrownPower;
        _t = 0;
    }

    public void activate() {
        _isRuning = true;
    }

    public void deactivate() {
        _isRuning = false;
    }
    
    public void reset()
    {
        _t=0;
        _throwAngle = 0;
        _thrownPower = 0;        
    }

    public void run(Sprite sprite) {
        if (_isRuning) {
            double dt = 0.7;
            if (_t > 0) {
                double x = _thrownPower * Math.cos(_throwAngle) * dt;
                double y = _thrownPower * Math.sin(_throwAngle) * dt - GRAVITY * dt * (2 * _t + dt) / 2;  
                sprite.move((int) x, -(int) y);
            }
            _t += dt;

        }
    }
}
